unit uScriptPage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, SynEditTypes,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls, SynEdit, SynEditHighlighter, SynHighlighterPas;

type

  TScriptTabSheet = class(TTabSheet)
  private
    FFileName: string;
    FSynEditor: TSynEdit;
    FBoTempFile: boolean;
    FBoChanged: boolean;
    procedure SetFileName(const AFileName: string);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure LoadFromFile(AFileName: string);
    function GetfileDesc: string;
    procedure TempSave(AFileName: string);
    property FileName: string read FFileName write SetFileName;
    property BotempFile: boolean read FBoTempFile;
    property Editor: TSynEdit read FSynEditor;
    property BoChanged: boolean read FBoChanged write FBoChanged;
  end;

implementation

{ TScriptTabSheet }

constructor TScriptTabSheet.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FBoTempFile := true;
  FSynEditor := TSynEdit.Create(self);
  FSynEditor.Parent := Self;
  FSynEditor.Align := alClient;
  FileName := 'temp.pas';
end;

destructor TScriptTabSheet.Destroy;
begin
  inherited;
end;

function TScriptTabSheet.GetfileDesc: string;
begin
  if FBoTempFile then
  begin
    Result := 'Temp File';
  end
  else
    Result := FileName;
end;

procedure TScriptTabSheet.LoadFromFile(AFileName: string);
begin
  if AFileName <> '' then
  begin
    FSynEditor.Lines.LoadFromFile(AFileName);
    FileName := AFileName;
    FBoTempFile := false;
  end;
end;

procedure TScriptTabSheet.SetFileName(const AFileName: string);
begin
  FFileName := AFileName;
  Caption := ExtractFileName(AFileName);
end;

procedure TScriptTabSheet.TempSave(AFileName: string);
begin
  if FBoTempFile then
  begin
    FileName := AFileName;
    FBoTempFile := false;
    FBoChanged:=false;
    FSynEditor.Modified:=false;
    FSynEditor.Lines.SaveToFile(AFileName);
  end;
end;

end.

